package com.iwhalecloud.bss.kite.cucc.web.service.accept.handler.module;

import com.iwhalecloud.bss.kite.client.vo.scene.CommonAttrModuleVO;
import com.iwhalecloud.bss.kite.common.constant.KeyConsts3;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.dataservice.cache.DcPublicCache;
import com.iwhalecloud.bss.kite.dataservice.cache.OfferCache;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.web.service.accept.bo.AcceptContext;
import com.iwhalecloud.bss.kite.web.service.accept.bo.SceneModule;
import com.iwhalecloud.bss.kite.web.service.accept.handler.module.CommonAttrModuleHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BackReasonOperationModleHandler extends CommonAttrModuleHandler {
    @Autowired
    private IQuerySceneInstService querySceneInstService;

    @Override
    public CommonAttrModuleVO dealExecuteSpecialAttr(AcceptContext context, SceneModule sceneModule, CommonAttrModuleVO defCommonAttrInfoVO) {
        this.removeCommonAttr(context, sceneModule, defCommonAttrInfoVO);
        return defCommonAttrInfoVO;
    }

    @Override
    public CommonAttrModuleVO dealPreviewSpecialAttr(AcceptContext context, SceneModule sceneModule, CommonAttrModuleVO defCommonAttrInfoVO) {
        this.removeCommonAttr(context, sceneModule, defCommonAttrInfoVO);
        return defCommonAttrInfoVO;
    }
    private CommonAttrModuleVO removeCommonAttr(AcceptContext context, SceneModule sceneModule, CommonAttrModuleVO defCommonAttrInfoVO) {
        //物联网重提展示退单原因 其他不展示
        String nodeCode = querySceneInstService.getExtParameterValue(context.getSceneVo().getSceneInstId(), "nodeCode", "");
        //融合产品变更时主产品属性不可编辑
        //offerInst.get
        String offerId = context.getAcceptRequest().getOfferId();
        String objId = OfferCache.get(offerId).getAttrValue("cateId");
        if((!KiteStringUtils.equals(nodeCode, KeyConsts3.ORDER_RESUBMIT)||!KiteStringUtils.equalsAny(objId, DcPublicCache.getCodeb("210728701", "wlwCate").split(",")))){
            //defCommonAttrInfoVO.getCommonAttrList().removeIf(commAttr -> KiteStringUtils.equalsAny(commAttr.getFieldName(), "BackReason"));
            defCommonAttrInfoVO.setIsShow("F");
        }
        return null;
    }
}
